const err = require("../constant/err.type.js");
const {Gzgj,Poi,Updata,Nodes} = require("../common/file.js");
const {DATA_PATH} = require("../config/config.default.js");
const gzgj = new Gzgj(`${DATA_PATH}Js_GZGJ.json`);
const poi = new Poi(`${DATA_PATH}Js_POI.json`);
const updata = new Updata(`${DATA_PATH}Js_UpData.json`);
const {getConfig,saveConfig} = require("../controller/configs.controller.js");
const { getGaojing } = require("./common");
//设置故障告警
const setAlarm = async (list,link,host) =>{
    try {
        var res;
        var resData = {code:-1,msg:"",data:""}
        var {linkId,linkName,status,statusValue,lineName,times,cancat,works,attenuations} = link;
        if(!linkId || linkId <= 0){
            resData.msg = "线路ID错误";
            return resData;
        }
        if(!linkName || linkName == ''){
            resData.msg = "线路名称错误";
            return resData;
        }
        if(!status || status == ''){
            resData.msg = "线路状态错误";
            return resData;
        }
        if(!statusValue || statusValue == ''){
            resData.msg = "线路状态值错误";
            return resData;
        }
        if(!lineName || lineName == ''){
            resData.msg = "链路名称错误";
            return resData;
        }
        if(!times || times == ''){
            resData.msg = "建设时间错误";
            return resData;
        }
        if(!cancat || cancat == ''){
            resData.msg = "联系人错误";
            return resData;
        }
        if(!works || works == ''){
            resData.msg = "业务名称错误";
            return resData;
        }
        if(!attenuations || attenuations == ''){
            resData.msg = "衰减值错误";
            return resData;
        }
        if(!list || !(list instanceof Array) || list.length < 0){
            resData.msg = "节点列表不能为空";
            return resData;
        }
        if(!host || host == ''){
            resData.msg = "主机地址不能为空";
            return resData;
        }
        res = getGaojing(list,statusValue);
        if(res.code == 0){
            let point = {ID:`GZGJ${linkId}`,Class:"GZ",Name:`BP_POI_GZGJ${linkId}`,Show_Name:linkName,Mesh:"SM_GZGJ",X:res.data.x,Y:res.data.y,Z:"8000",URL:`http://${host}/gzgj?linkId=${linkId}`,Build:"1",Visible:"1",Click:"1",Init:"0",R:"1",G:"0",B:"0",Color:""}
            let list = [];
            list.push(point);
            let is = gzgj.setValue({values:list,keyName:"linkName",wvalue:`GZGJ${linkId}`,defaults:false});
            if(!is){
                ctx.app.emit("error",err.setDefaultValue({code:-1,msg:"写入Js_GZGJ.json失败",data:""}),ctx);
                return;
            }
            
        }
        
        
    } catch (error) {
        
    }
}